package com.uniledger.exchange.home.scheme;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.uniledger.commonlib.easymoney.EasyMoneyTextView;
import com.uniledger.commonlib.view.FullListView;
import com.uniledger.exchange.HomeActivity;
import com.uniledger.exchange.R;
import com.uniledger.exchange.base.activity.BaseActivity;
import com.uniledger.exchange.model.OkSingleton;

import java.util.List;

import butterknife.BindString;
import butterknife.BindView;

public class PayOkActivity extends BaseActivity {

    public static void start(Activity activity, PayResult payResult) {
        Intent intent = new Intent(activity, PayOkActivity.class);
        intent.putExtra("PayThirdResult", payResult);
        activity.startActivity(intent);
    }

    @BindView(R.id.img_icon)
    ImageView head;

    @BindView(R.id.txt_desc_ok)
    TextView txt_desc_ok;

    @BindView(R.id.txt_desc_info)
    EasyMoneyTextView txt_desc_info;

    @BindView(R.id.pay_list)
    FullListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_ok);
    }

    @Override
    public void initBar() {
        super.initBar();
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        toolbar.setTitle("");
    }

    @BindString(R.string.pay_ok_label_success)
    String success;

    @Override
    public void getParams() {
        PayResult payResult = getIntent().getParcelableExtra("PayThirdResult");

        txt_desc_ok.setText(payResult.flagStr + success);
        txt_desc_info.setText(payResult.amount);
        txt_desc_info.setCurrencySymbol(OkSingleton.getInstance().getSymbol());

        List<PayDesc> list = PayDesc.payDescList(this,payResult);
        PayCompleteAdapter adapter = new PayCompleteAdapter(list, this);
        listView.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_pay_complete, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.manger_pay_done) {
            HomeActivity.start(PayOkActivity.this);
            return true;
        } else {
            return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            //do something.
            return true;
        } else {
            return super.dispatchKeyEvent(event);
        }
    }
}
